package com.gitee.jktantan.datasource.monitor.analyze.p6spy;


import lombok.Getter;
import lombok.Setter;

/**
 * 借用Sqlparser里面的QueryEntry
 */
@Getter
@Setter
public class QueryEntry implements Comparable {
    private long time = 0;
    private long elapsedTime = 0;
    private String url;
    private String preparedSQL;
    private String sqlStatement;
    private String category;
    private String connectionID;
    private int receptionRank = 0;

    public int compareTo(Object o) {
        QueryEntry right = (QueryEntry) o;
        Long leftTime = new Long(getTime());
        Long rightTime = new Long(right.getTime());
        int timeCompare = leftTime.compareTo(rightTime);
        if (timeCompare != 0) {
            return timeCompare;
        } else {
            return new Integer(receptionRank).compareTo(new Integer(right.getReceptionRank()));
        }
    }

    public boolean equals(Object o) {
        return (compareTo(o) == 0);
    }

    public int hashCode() {
        return (Long.toString(time) + Integer.toString(receptionRank)).hashCode();
    }

}